greet lda $c030
 sta $c00c ;disable 80 columns (rev-e)
 sta $c000 ;disable '80store'
 jsr $fe84
 jsr $fb2f
 jsr $fe93
 jsr $fe89
 cld
* sei ; don't turn interrupts off!! *** see rev note #44 ***
 jsr home ;clear screen
 ldx #slin2-slin1-1 ;move greeting to screen.
grt1 lda slin1,x ;"apple ii"
 sta $4a8+20-4,x ;$4a8 starts the line.
 dex
 bpl grt1
 ldx #slin3-slin2-1
grt2 lda slin2,x ;"prodos (version)   (date)"
 sta $5a8+20-grtlz,x ;$5a8 starts the line
 dex
 bpl grt2
 ldx #slin4-slin3-1
grt3 lda slin3,x ;(blank line)
 sta $6a8+20-grtlzz,x ;$6a8 starts the line
 dex
 bpl grt3
 ldx #slin5-slin4-1
grt4 lda slin4,x
 sta $750,x ;$750 starts the line
 dex
 bpl grt4
 ldx #grt6-slin5-1
grt5 lda slin5,x
 sta $7d0+20-grtlzzz,x ;$7d0 starts the line
 dex
 bpl grt5
 lda $c030
 rts
*
slin1 asc 'APPLE II' ; 8 Chars Exactly
 ifeq os-prodos
slin2 asc 'PRODOS 8 V1.7        ' 
 fin
 ifeq os-ednet
slin2 asc 'prodos ednet 1.0x01  '
 fin
* change 72 <-------------------------------
 asc '08-AUG-88' ;date (no leading spaces unless date <10)
slin3 asc '            '
slin4 asc 'COPYRIGHT APPLE COMPUTER, INC., 1983-88' ;39 chars 
slin5 asc 'ALL RIGHTS RESERVED.'
grt6 equ *
grtlz equ slin3-slin2/2
grtlzz equ slin4-slin3/2
grtlzzz equ grt6-slin5/2
*
indrcn equ $10
devid equ $12
relc800 equ $cfff
drv1adr equ $bf10 
drv2adr equ $bf20 
lstdev equ $bf30 
* devcnt equ $bf31 
* devlst equ $bf32 
glbclk equ $bf06 
* sltbyt equ $bf99 
jump equ $4c
 page
***************************************************
*
* this routine finds all disk devices plugged into the
*  system's slots that follow apple's disk id convention.
*  the routine sets up the address and device table in
*  prodos's system global page.  13-sector disk ii's are 
*  not configured since they may not function properly in
*  the 16 sector mode...
*
* profiles, and other intelligent devices, are expected to
*  have roms containing the disk i/o drivers.
*
* this routine was revved 8/21/86 to make sure that correct number
*  of smartport devices are installed, and that disk //s are always
*  searched last by placing them at the end of the list.  disk // unit
*  numbers are stacked at the end of the device table, while regular
*  devices are stacked at the beginning.  after all slots have been
*  searched the two lists are combined. see note 60.
*
numdevices ds 8,0 ;eight bytes for smartport call
*
driveradr dw 0
d2idx dfb 0
diskins2 dfb 0 ;msb set if drive in slot 2
*
***************************************************
 skp 1
devsrch ldx #0
 stx dst
 stx dst+1
 stx indrcn ;set up for search.
 dex
 stx devcnt ;device count=none
 lda #14 ;start disk // area at the end of devlist
 sta d2idx
*********************** see note #65 ***********************
*
* make a quick check of slot 2.  if there is a disk card there
*  clear the msb of diskins2.  this will limit the number of
*  devices in any slot 5 smartport card to 2.
*
 lda #$c2
 sta indrcn+1 ;check slot 2
 jsr cmpid ;is there a disk card in slot 2??
 ror diskins2 ;clear msb if so, set otherwise
*
**********************************************************
*
 lda #$c7 ;search slots from high to low.
 sta indrcn+1
 skp 1
findsks1 equ *
*
***************** code here became a subroutine ****************
************************* see note #65 *************************
*
 jsr cmpid
 bcs nxtdsk ;carry set means no card this slot
*
****************************************************************
*
 lda (indrcn),y ;check last byte of $cn rom
 beq diskii ;if =00 then 16 sector disk ii.
 cmp #$ff ;if =ff then 13 sector disk ii.
 bcs nxtdsk ;ignore if 13 sector boot rom.
 sta driveradr ;else, assume it's an intelligent disk for now.
*
 ldy #7 ;check for a smartport device
 lda (indrcn),y
 bne nosport
 jmp smartport
*
nosport equ *
 ldy #$fe ;get attributes byte.
 lda (indrcn),y
 and #$03 ; & verify it provides read, write, and status calls
 cmp #$03
 sec ;assume it is a bozo brand disk...
 bne nxtdsk
 skp 1
 jsr setdevid
 clc
 php ;remember that it's not a disk //
 lsr a ;move # of units (0=1, 1=2) to carry.
 lda indrcn+1 ;low entry addr already on stack, save hi addr.
 bne adevice ;branch always taken.
 skp 1
diskii sta devid ;disk ii's have nul attributes
 sec
 php ;remember it's a disk //
 lda d2blkio
 sta driveradr
 lda d2blkio+1
*
* the carry is already set telling installdev to install two devices
*  for disk //s.
*
adevice equ *
 sta driveradr+1
*
 jsr installdev ;install one or two devices this slot
*
 plp ;get back if it's disk //
 bcc nodisk2
*
 dex ;move the list pointer back
 dex devcnt ;(installdev left x set)
 stx devcnt
 dec d2idx ;increase the disk two index
 dec d2idx
 ldy d2idx
*
 inx ;increase x in case =$ff
 lda devlst+1,x ;
 sta devlst,y
 lda devlst,x
 sta devlst+1,y
 dex ;back to devcnt again
*
nodisk2 equ *
*
*------------------------------------------------------------------
*
******************* see rev note #53 & #54 **********************
*
*ldy #$7 ; check smartport id rom byte at $cn07...
*lda (indrcn),y ; is it a $0?
*bne notsmartport ; branch if not.
*lda indrcn+1 ; now we are only special casing slot 5!
*cmp #$c5 ; is the smartport card in $c500 space?
*bne notsmartport ; branch if not.
*inx ; get to next unit number in devlst.
*lda #$2b ; deposit unit number $2b(slot 2, drive 1)
*sta devlst,x ; in devlst. (smartport unit 3)
*inx ; bump to next spot in devlst.
*lda #$ab ; deposit unit number $ab(slot 2, drive 2)
*sta devlst,x ; in devlst. (smartport unit 4)
*stx devcnt ; update device count.
*lda #$c5 ; now update hi byte
*sta drv1adr+5 ; of driver entry addresses...
*sta drv2adr+5 ; 
*lda drv1adr+10 ; get low driver entry address...
*sta drv1adr+4 ; and update low bytes of
*sta drv2adr+4 ; driver entry addresses...
*notsmartport equ *
***********************************************
* -------------------- see rev note 33 ------------------------
* -------------------- see rev note 24 ----------------------
*lda indrcn+1 ;get slot #
*cmp #$c5 ;only slots 5 & 6 allow drives 3 & 4
*bcc nmdrvs ;  to be mapped into slot (#-4)
*cmp #$c7
*bcs nmdrvs
*lda devid
*and #$2 ;check for 3 or 4 drives
*beq nmdrvs ;branch if not
*lda devid
*lsr a ;move 4 drive bit into carry
*php ;  and save it.
*lda indrcn+1 ;get index to global device table for
*pha
*and #3 ;  this slot and map into lower slot.
*asl a
*tay
*pla
*and #7 ;use index again to..
*asl a
*asl a
*asl a ;  form device number.
*asl a
*and #$3f
*jsr stadrv
*plp ;get bit showing if 4 drives back
*ror a ;if 4 drives, then bit 7=1.
*bpl nodrv4 ;branch if a 3-drive device
*inx ;else assume that 4th drive is present.
*sta devlst,x ;  and add it to the device list.
*nodrv4 stx devcnt ;save updated device count.
*asl a ;shift # of drives back into carry.
*lda drv1adr+8,y ;get low address from parent slot
*pha
*lda indrcn+1 ;get high address of device driver.
*sta drv1adr+1,y ;save it in down-mapped slot
*bcc ndrv4a ;branch if 3 drives
*sta drv2adr+1,y ;save high address of drive 4
*pla 
*pha
*sta drv2adr,y ;save low address for drive 4.
*ndrv4a pla ;now save low address for drive 3
*sta drv1adr,y
*nmdrvs equ *
* -----------------------------------------------------------
*
nxtdsk2 equ *
 clc
 skp 1
nxtdsk jsr sltrom ;test for clock & other devices
 skp 1
 dec indrcn+1 ;set up for next lower slot.
 lda indrcn+1 ;have all slots been checked?
 and #7
 beq *+5 ;(to the tay)
 jmp findsks1 ;branch if not.
*
* now copy the disk // list to the end of the regular list
*  start by making the device count include disk //s
*
 ldx devcnt ;load up current devcnt-1
 lda #14
 sec
 sbc d2idx
 beq d2snone ;if there were no disk //s, forget it
*
 clc
 adc devcnt ;sum of disk //s and others
 sta devcnt
*
 inx ;move to open space in regular list
 ldy #13 ;first disk // entry
*
mlab equ *
 lda devlst,y
 pha
 lda devlst,x
 sta devlst,y
 pla
 sta devlst,x
*
 inx
 dey
 sty d2idx ;use as a temp
 cpx d2idx
 blt mlab ;continue 'til indices cross...
*
d2snone equ *
 ldy #0
 ldx devcnt ;now change the device order
srtdsk1 lda devlst,x ; so that the boot device
 pha
 and #$7f 
 eor lstdev ; will have highest priority
 asl a
 bne srtdsk2
 pla
 iny
srtdsk2 dex
 bpl srtdsk1
 ldx devcnt ;now reverse order of search, hi to lo.
 tya ;was boot device found?
 beq srtdsk3 
 lda lstdev ;make boot device first in search order.
 sta devlst,x
 dex
 bmi dsrend ;branch if only one device.
 dey  ;is this a 2 drive device?
 bmi srtdsk3 ;branch if not.
 eor #$80 ;make boot device, drive 2 next.
 sta devlst,x
 dex
 bmi dsrend ;branch if only one device, 2 drives. 
srtdsk3 pla
 sta devlst,x
 dex
 bpl srtdsk3 
dsrend jsr fndtrd ;save accumuated machine id. 
 beq whosit
 sta machid
 rts 
 skp 1
whosit jmp whatsit
 skp 1
stadrv equ *
 ora devid ;combine with attributes.
 ldx devcnt
 inx ;put device number into device list.
 sta devlst,x
 asl a ;now form drive 2 device number, if any.
 rts
 skp 1
*
sltrom bcc isrom ;branch if disk drive.
 ldy #6 ;test this slot for clock card.
clkchk lda (indrcn),y
 cmp clkid,y 
 bne notclk ;branch if not clock. 
 dey
 dey
 bpl clkchk
 lda indrcn+1 ;transfer high slot addr minus $c1 (default) 
 sbc #$c1 ; to relocate references to clock rom. 
 sta clock64
 lda #jump ;also enable jump vector in globals. 
 sta glbclk
 lda apple ;mark clock as present
 beq dsrend 
 ora #1
 sta apple
 bne isrom ;branch always taken.
 skp 1
notclk ldy #5 ;test for 80 col card.
 lda (indrcn),y ; byte at a time.
 cmp #$38
 bne notcons
 ldy #7 ;test values are same as pascal's
 lda (indrcn),y
 cmp #$18
 bne notcons
 ldy #$b
 lda (indrcn),y
 cmp #1
 bne notcons
 iny
 lda (indrcn),y
 and #$f0 ;mask off low nibble
 cmp #$80 ;generic for 80-col card
 bne notcons
 lda apple 
 beq dsrend 
 ora #2
 sta apple ;mark config for 80 col. present.
 bne isrom ;branch always taken.
 skp 1
notcons ldy #0 ;test for any rom.
 ldx #0
 lda (indrcn),y
 cmp #$ff ;test for apple iii non slot.
 beq norom ;branch if invalid rom.
tstrom cmp (indrcn),y ;look for floating bus.
 bne norom
 inx ;loop 256 times.
 bne tstrom
isrom lda indrcn+1 ;mark a bit in slot byte
 and #$7 ; to indicate rom present.
 tax
 lda sltbit,x
 ora sltbyt
 sta sltbyt
norom rts 
 skp 1
d2blkio dw rwts
dskid equ *
clkid dfb $08,$20,$28,$00,$58,$03,$70,$3c
sltbit dfb $00,$02,$04,$08,$10,$20,$40,$80
 skp 1
fndtrd clc 
 ldy sltbit
ftrad1 lda (look),y
 and #$df
 adc sltbit
 sta sltbit
 rol sltbit
 iny
 cpy sltbit+3
 bne ftrad1
 tya
 asl a
 asl a
 asl a
 asl a
 tay
 eor sltbit
 adc #$b
 bne ftrad2
 lda apple
 rts
ftrad2 lda #0 
 rts
*
installdev equ * ;made a sub 8/21/86
 php ;and how many drives (carry).
 lda indrcn+1 ;get index to global device table for
 and #7 ;this slot
 asl a
 tay ; ... into y reg.
 asl a
 asl a ;now form device number.
 asl a
 jsr stadrv
 plp
 ror a ;if 2 drives, then bit 7=1.
 bpl nodrv2 ;branch if a 1-drive device (i.e. profile)
 inx ;else presume that second drive is present.
 sta devlst,x
nodrv2 stx devcnt ;save updated device count.
 asl a ;shift # of drives back into carry.
 lda driveradr ;get high address of device driver.
 sta drv1adr,y
 bcc ndrv2a ;branch if single drive
 sta drv2adr,y
ndrv2a equ *
 lda driveradr+1
 sta drv1adr+1,y
 bcc ndrv2b
 sta drv2adr+1,y
ndrv2b equ *
 rts
*
*
* this piece of code (not a subroutine) is branched to if the slot
*  search code finds a smartport device.  it does a smartport status
*  call (code = 0) to determine the number of devices connected to
*  the "card".  it then installs from 0..4 units in the table.
*
smartport equ *
 jsr setdevid ;set up the devid byte from attributes
*
* only map more than two devices if card is in slot 5
*
 lda indrcn+1
 sta driveradr+1 ;didn't set this yet
*cmp #$c5
*bne donesp
*
* do the call to smartport to get the number of devices
*
 lda driveradr
 skp 1
*********************************************
* patch 74
*********************************************
 skp 1
 sta pscall+1 ;modify operand
 skp 2
 clc
 adc #3
 sta spcall+1
 lda driveradr+1 ;no page cross possible
 sta spcall+2
 skp 1
*********************************************
* patch 74
*********************************************
 skp 1
 sta pscall+2 ;modify operand
 asl  ;convert $cn to $n0
 asl  ;
 asl  ;
 asl  ;
 sta $43 ;unit number
 lda #$00 ;clear a few bytes
 sta $42 ;force a prodos status call
 sta $44 ;dummy pointer
 sta $46 ;number of bytes to transfer
 sta $47 ;number of bytes to transfer
 lda #$10 ;dummy pointer should be <>0
 sta $45 ;dummy pointer
 skp 1
*********************************************
* patch 74
*********************************************
 skp 1
pscall equ * ;prodos status call
 jsr $0 ;filled in by above code
 skp 1
spcall equ *
 jsr $0 ;filled in by above code
 dfb $0 ;this is a status call
 dw spcallparms
*
* don't add devices if there are none connected
*
 lda numdevices
 beq donesp
*
* do the first and second device if it exists
*
 cmp #2 ;c set if 2,3,4
 jsr installdev
*
* do the third and fourth drives if they exist
*  they cannot exist for any card other than one in slot 5
*
 lda indrcn+1
 cmp #$c5
 bne donesp
*
********************* see note #65 *********************
*
* if this is slot 5, and if there is a disk card in slot 2,
*  only install 2 devices this slot.  thank you.
*
 bit diskins2 ;is there a disk in slot two?
 bpl donesp
*
********************************************************
*
 lda numdevices
 cmp #3 ;c set if 3,4,...
 blt donesp
 cmp #4 ;c set if 4,5,6,...
 lda #$c2 ;make it think it's slot 2
 sta indrcn+1
 jsr installdev
 lda #$c5
 sta indrcn+1
*
donesp equ *
 jmp nxtdsk2 ;we know it's a disk device
*
*
setdevid equ *
 ldy #$fe
 lda (indrcn),y
 lsr a
 lsr a
 lsr a
 lsr a
 sta devid
 rts
*
*
************** moved from inline ****************
**************   see note #65    ****************
*
* input:   indrcn -  point to $cn00 of mystery card
* output:  carry    clear if disk card here, set ow
*          y        $ff
*
cmpid equ *
 lda relc800 ;release $c800 space from previous slot.
 ldy #$5 
cmpid2 lda (indrcn),y ;compare id bytes.
 cmp dskid,y ;$cn07=don't care. 
 sec
 bne cibye ;$cn05=03 
 dey ;$cn03=00
 dey ;$cn01=20
 bpl cmpid2 ;loop until all 4 id bytes match.
 clc
cibye equ *
 rts
*
*************************************************
*
* smartport parameter area
*
spcallparms equ *
 dfb 3 ;number of parameters
 dfb 0 ;unit number (code for smartport stat)
 dw numdevices
 dfb 0 ;status code = 0 (code for general status)
*
*--------------------------------------------------------------------
*
*  the original code (previous to the 8/21/86 revision) see note 60
*
*
*
*greet lda $c030
*sta $c00c ;disable 80 columns (rev-e)
*sta $c000 ;disable '80store'
*jsr $fe84
*jsr $fb2f
*jsr $fe93
*jsr $fe89
*cld
** sei ; don't turn interrupts off!! *** see rev note #44 ***
*jsr home ;clear screen
*ldx #slin2-slin1-1 ;move greeting to screen.
*grt1 lda slin1,x ;"apple ii"
*sta $4a8+20-4,x ;$4a8 starts the line.
*dex
*bpl grt1
*ldx #slin3-slin2-1
*grt2 lda slin2,x ;"prodos (version)   (date)"
*sta $5a8+20-grtlz,x ;$5a8 starts the line
*dex
*bpl grt2
*ldx #slin4-slin3-1
*grt3 lda slin3,x ;(blank line)
*sta $6a8+20-grtlzz,x ;$6a8 starts the line
*dex
*bpl grt3
*ldx #grt5-slin4-1
*grt4 lda slin4,x
*sta $7d0,x ;$7d0 starts the line
*dex
*bpl grt4
*lda $c030
*rts
*
*slin1 asc 'apple ii' ;8 chars 
*ifeq os-prodos
*slin2 asc 'prodos 8 v1.2a1      '
*fin
*ifeq os-ednet
*slin2 asc 'prodos ednet 1.0x01  '
*fin
*date
*slin3 asc '            '
*slin4 asc 'copyright apple computer, inc., 1983-86' ;39 chars 
*grt5 equ *
*grtlz equ slin3-slin2/2
*grtlzz equ slin4-slin3/2
*
*indrcn equ $10
*devid equ $12
*relc800 equ $cfff
*drv1adr equ $bf10 
*drv2adr equ $bf20 
*lstdev equ $bf30 
** devcnt equ $bf31 
** devlst equ $bf32 
*glbclk equ $bf06 
** sltbyt equ $bf99 
*jump equ $4c
*page
*rep 60
*
** this routine finds all disk devices plugged into the
**  system's slots that follow apple's disk id convention.
**  the routine sets up the address and device table in
**  prodos's system global page.  13-sector disk ii's are 
**  not configured since they may not function properly in
**  the 16 sector mode...
**
** profiles, and other intelligent devices, are expected to
**  have roms containing the disk i/o drivers.
**
*rep 60
*skp 1
*devsrch ldx #0
*stx dst
*stx dst+1
*stx indrcn ;set up for search.
*dex
*stx devcnt ;device count=none
*lda #$c7 ;search slots from high to low.
*sta indrcn+1
*skp 1
*findsks1 lda relc800 ;release $c800 space from previous slot.
*ldy #$5 
*cmpid lda (indrcn),y ;compare id bytes.
*cmp dskid,y ;$cn07=don't care. 
*sec
*bne nxtdsk1 ;$cn05=03 
*dey ;$cn03=00
*dey ;$cn01=20
*bpl cmpid ;loop until all 4 id bytes match.
*lda (indrcn),y ;check last byte of $cn rom
*beq diskii ;if =00 then 16 sector disk ii.
*cmp #$ff ;if =ff then 13 sector disk ii.
*bcs nxtdsk1 ;ignore if 13 sector boot rom.
*pha ;else, assume it's an intelligent disk for now.
*dey ;get attributes byte.
*lda (indrcn),y
*pha ; & verify it provides read, write, and status calls
*and #$03
*cmp #$03
*beq smart ;branch if it does.
*pla ;else assume it is bozo brand disk...
*pla
*sec
*nxtdsk1 jmp nxtdsk ;branch always taken.
*skp 1
*smart pla ;get attributes again.
*lsr a
*lsr a
*lsr a
*lsr a ;move upper 4 bits to lower 4 bits of the devnum.
*sta devid
*lsr a ;move # of units (0=1, 1=2) to carry.
*lda indrcn+1 ;low entry addr already on stack, save hi addr.
*bne adevice ;branch always taken.
*skp 1
*diskii sta devid ;disk ii's have nul attributes
*lda d2blkio ;save low and hi addr for
*pha ; disk ii block i/o routine.
*lda d2blkio+1
*sec ;indicate possibly 2 drives per slot.
*adevice pha ;save vector address for now.
*php ;and how many drives (carry).
*lda indrcn+1 ;get index to global device table for
*and #7 ;this slot
*asl a
*tay ; ... into y reg.
*asl a
*asl a ;now form device number.
*asl a
*jsr stadrv
*plp
*ror a ;if 2 drives, then bit 7=1.
*bpl nodrv2 ;branch if a 1-drive device (i.e. profile)
*inx ;else presume that second drive is present.
*sta devlst,x
*nodrv2 stx devcnt ;save updated device count.
*asl a ;shift # of drives back into carry.
*pla ;get high address of device driver.
*sta drv1adr+1,y
*bcc ndrv2a ;branch if single drive
*sta drv2adr+1,y
*pla
*pha
*sta drv2adr,y ;save low address for drive 2.
*ndrv2a pla ;now save low address for drive 1 driver.
*sta drv1adr,y
**
******************* see rev note #53 & #54 **********************
**
*ldy #$7 ; check smartport id rom byte at $cn07...
*lda (indrcn),y ; is it a $0?
*bne notsmartport ; branch if not.
*lda indrcn+1 ; now we are only special casing slot 5!
*cmp #$c5 ; is the smartport card in $c500 space?
*bne notsmartport ; branch if not.
*inx ; get to next unit number in devlst.
*lda #$2b ; deposit unit number $2b(slot 2, drive 1)
*sta devlst,x ; in devlst. (smartport unit 3)
*inx ; bump to next spot in devlst.
*lda #$ab ; deposit unit number $ab(slot 2, drive 2)
*sta devlst,x ; in devlst. (smartport unit 4)
*stx devcnt ; update device count.
*lda #$c5 ; now update hi byte
*sta drv1adr+5 ; of driver entry addresses...
*sta drv2adr+5 ; 
*lda drv1adr+10 ; get low driver entry address...
*sta drv1adr+4 ; and update low bytes of
*sta drv2adr+4 ; driver entry addresses...
*notsmartport equ *
***********************************************
* -------------------- see rev note 33 ------------------------
* -------------------- see rev note 24 ----------------------
*lda indrcn+1 ;get slot #
*cmp #$c5 ;only slots 5 & 6 allow drives 3 & 4
*bcc nmdrvs ;  to be mapped into slot (#-4)
*cmp #$c7
*bcs nmdrvs
*lda devid
*and #$2 ;check for 3 or 4 drives
*beq nmdrvs ;branch if not
*lda devid
*lsr a ;move 4 drive bit into carry
*php ;  and save it.
*lda indrcn+1 ;get index to global device table for
*pha
*and #3 ;  this slot and map into lower slot.
*asl a
*tay
*pla
*and #7 ;use index again to..
*asl a
*asl a
*asl a ;  form device number.
*asl a
*and #$3f
*jsr stadrv
*plp ;get bit showing if 4 drives back
*ror a ;if 4 drives, then bit 7=1.
*bpl nodrv4 ;branch if a 3-drive device
*inx ;else assume that 4th drive is present.
*sta devlst,x ;  and add it to the device list.
*nodrv4 stx devcnt ;save updated device count.
*asl a ;shift # of drives back into carry.
*lda drv1adr+8,y ;get low address from parent slot
*pha
*lda indrcn+1 ;get high address of device driver.
*sta drv1adr+1,y ;save it in down-mapped slot
*bcc ndrv4a ;branch if 3 drives
*sta drv2adr+1,y ;save high address of drive 4
*pla 
*pha
*sta drv2adr,y ;save low address for drive 4.
*ndrv4a pla ;now save low address for drive 3
*sta drv1adr,y
*nmdrvs equ *
* -----------------------------------------------------------
*clc
*skp 1
*nxtdsk jsr sltrom ;test for clock & other devices
*skp 1
*dec indrcn+1 ;set up for next lower slot.
*lda indrcn+1 ;have all slots been checked?
*and #7
*beq *+5 ;(to the tay)
*jmp findsks1 ;branch if not.
*skp 1
*tay ;make y=0
*ldx devcnt ;now change the device order
*srtdsk1 lda devlst,x ; so that the boot device
*pha
*and #$7f 
*eor lstdev ; will have highest priority
*asl a
*bne srtdsk2
*pla
*iny
*srtdsk2 dex
*bpl srtdsk1
*ldx devcnt ;now reverse order of search, hi to lo.
*tya ;was boot device found?
*beq srtdsk3 
*lda lstdev ;make boot device first in search order.
*sta devlst,x
*dex
*bmi dsrend ;branch if only one device.
*dey ;is this a 2 drive device?
*bmi srtdsk3 ;branch if not.
*eor #$80 ;make boot device, drive 2 next.
*sta devlst,x
*dex
*bmi dsrend ;branch if only one device, 2 drives. 
*srtdsk3 pla
*sta devlst,x
*dex
*bpl srtdsk3 
*dsrend jsr fndtrd ;save accumuated machine id. 
*beq whosit
*sta machid
*rts 
*skp 1
*whosit jmp whatsit
*skp 1
*stadrv equ *
*ora devid ;combine with attributes.
*ldx devcnt
*inx ;put device number into device list.
*sta devlst,x
*asl a ;now form drive 2 device number, if any.
*rts
*skp 1
*sltrom bcc isrom ;branch if disk drive.
*ldy #6 ;test this slot for clock card.
*clkchk lda (indrcn),y
*cmp clkid,y 
*bne notclk ;branch if not clock. 
*dey
*dey
*bpl clkchk
*lda indrcn+1 ;transfer high slot addr minus $c1 (default) 
*sbc #$c1 ; to relocate references to clock rom. 
*sta clock64
*lda #jump ;also enable jump vector in globals. 
*sta glbclk
*lda apple ;mark clock as present
*beq dsrend 
*ora #1
*sta apple
*bne isrom ;branch always taken.
*skp 1
*notclk ldy #5 ;test for 80 col card.
*lda (indrcn),y ; byte at a time.
*cmp #$38
*bne notcons
*ldy #7 ;test values are same as pascal's
*lda (indrcn),y
*cmp #$18
*bne notcons
*ldy #$b
*lda (indrcn),y
*cmp #1
*bne notcons
*iny
*lda (indrcn),y
*and #$f0 ;mask off low nibble
*cmp #$80 ;generic for 80-col card
*bne notcons
*lda apple 
*beq dsrend 
*ora #2
*sta apple ;mark config for 80 col. present.
*bne isrom ;branch always taken.
*skp 1
*notcons ldy #0 ;test for any rom.
*ldx #0
*lda (indrcn),y
*cmp #$ff ;test for apple iii non slot.
*beq norom ;branch if invalid rom.
*tstrom cmp (indrcn),y ;look for floating bus.
*bne norom
*inx ;loop 256 times.
*bne tstrom
*isrom lda indrcn+1 ;mark a bit in slot byte
*and #$7 ; to indicate rom present.
*tax
*lda sltbit,x
*ora sltbyt
*sta sltbyt
*norom rts 
*skp 1
*d2blkio dw rwts
*dskid equ *
*clkid dfb $08,$20,$28,$00,$58,$03,$70,$3c
*sltbit dfb $00,$02,$04,$08,$10,$20,$40,$80
*skp 1
*fndtrd clc 
*ldy sltbit
*ftrad1 lda (look),y
*and #$df
*adc sltbit
*sta sltbit
*rol sltbit
*iny
*cpy sltbit+3
*bne ftrad1
*tya
*asl a
*asl a
*asl a
*asl a
*tay
*eor sltbit
*adc #$b
*bne ftrad2
*lda apple
*rts
*ftrad2 lda #0 
*rts
v